There are many situations where it is useful to count the number of zeros in a binary number starting from the either the left hand side (i.e. starting with the most significant bit (MSB)) or the right hand side (i.e. starting with the least significant bit (LSB)). When counting from the most significant bit, this may be referred to as counting leading zeros (e.g. such that a binary number 0111 has one leading zero) and when counting from the least significant bit this may be referred to as counting trailing zeros (e.g. such that a binary number 1110 has one trailing zero and a binary number 1000 has three trailing zeros).
A leading zero counter (which is so called as it counts the leading zeros) may, for example, be used in subtraction and for normalization in floating point arithmetic. It will be appreciated, however, that a trailing zero counter (which is so called as it counts the trailing zeros) also may be used as a leading zero counter, and vice versa, by connecting up the inputs such that the true MSB of the input binary number is connected to the LSB input of the trailing/leading zero counter.
The embodiments described below are not limited to implementations which solve any or all of the disadvantages of known leading or trailing zero counters.